package com.qtummatrix.controller;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.qtummatrix.entity.CustomerInfoVO;
import com.qtummatrix.entity.CustomerinfoEntity;
import com.qtummatrix.service.CustomerNewService;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller("customernewAction")
public class customerNewController extends ActionSupport implements ModelDriven<CustomerinfoEntity> {

    private CustomerinfoEntity customerinfoEntity = new CustomerinfoEntity();


    public void setCustomerinfoEntity(CustomerinfoEntity customerinfoEntity) {
        this.customerinfoEntity = customerinfoEntity;
    }

    @Autowired
    private CustomerNewService customerNewService;

    Map<String, Object> info = new HashMap<String, Object>();


    public Map<String, Object> getInfo() {
        return info;
    }


    public void setInfo(Map<String, Object> info) {
        this.info = info;
    }


    public String findName() {
        HttpServletRequest req = ServletActionContext.getRequest();
        String id1 = req.getParameter("id");
        int id = Integer.parseInt(id1);
        List<CustomerInfoVO> list = customerNewService.findCustomerName(id);
        info.put("Customerlist", list);

        return SUCCESS;
    }

    public String update() {
        customerNewService.updateMessage(customerinfoEntity.getId(), customerinfoEntity.getCustomername(),
                customerinfoEntity.getGender(), customerinfoEntity.getTel(), customerinfoEntity.getUid(),
                customerinfoEntity.getAddress(), customerinfoEntity.getCustomerwork(),
				customerinfoEntity.getCustomertype(),
                customerinfoEntity.getDiscredit(), customerinfoEntity.getLitigation(),
				customerinfoEntity.getMonthlyincome(),
                customerinfoEntity.getBankid(), customerinfoEntity.getGoodsid(), customerinfoEntity.getCustomerstate()
                , String.valueOf(customerinfoEntity.getCreatetime(new Date())));

        return SUCCESS;
    }


    @Override
    public CustomerinfoEntity getModel() {
        // TODO Auto-generated method stub
        return customerinfoEntity;
    }

}
